<?php
class ApiController extends Controller
{
public function actionUpload()
        {
                $tempFolder=Yii::getPathOfAlias('webroot').'/upload/temp/';
 
                mkdir($tempFolder, 0777, TRUE);
                mkdir($tempFolder.'chunks', 0777, TRUE);
 
                Yii::import("ext.EFineUploader.qqFileUploader");
 
                $uploader = new qqFileUploader();
                $uploader->allowedExtensions = array('jpg','jpeg');
                $uploader->sizeLimit = 2 * 1024 * 1024;//maximum file size in bytes
                $uploader->chunksFolder = $tempFolder.'chunks';
 
                $result = $uploader->handleUpload($tempFolder);
                $result['filename'] = $uploader->getUploadName();
                $result['folder'] = $webFolder;
 
                $uploadedFile=$tempFolder.$result['filename'];
 
                header("Content-Type: text/plain");
                $result=htmlspecialchars(json_encode($result), ENT_NOQUOTES);
                echo $result;
                Yii::app()->end();
        }
        
        
        public function actionSaveAvatar(){
        	//文件保存路径
        	$savepath = '/public/uploads/';
        	//调用扩展
        	$avatar = $this->Widget('application.extensions.avatar.avatar', array(
        			//'uploadurl' => '.',
        			//'upload' => '/uploads/',
        			'savepath'  => $savepath,
        			'max_size'  => 300000,
        			'fileElementName' => $_REQUEST['id'],
        			'file_ext' => 'image',
        			'type' => 'image',
        			'iscut' => true,
        			'thumbname' => 'avatar',
        			'cutsize' => array('212'=>array(212,212),'big'=>array(112,112),'middle'=>array(48,48),'small'=>array(36,36),'micro'=>array(24,24)),
        	));
        	echo $avatar->Fileupload();
        }
        
        
        public function actionAjaxAction() {
        	$item = new Item();
        	$item->attributes = $_POST['Item'];
        	$file = CUploadedFile::getInstance ( $item, 'image' );
        	if ($file){
        		echo '1111';
        	}
        	else 
        		var_dump($_POST['Item']);
        	//var_dump($_POST['item_content']);
     /*
	        $dir = '/mnt/hgfs/PHP/vxwebsite/public/' . date ( 'Y' ) . '/' . date ( 'm' );
			if (! is_dir ( $dir ))
				mkdir ( $dir, 0777, 1 );
					
		
			$file = CUploadedFile::getInstance ( $model, 'item_content' );
			$newName = substr ( md5 ( $file->extensionName . round ( (microtime ( true ) * 1000) ) ), 0, 17 ) . '.' . $file->extensionName;
			$file_name = $dir . '/' . $newName;
			$file->saveAs ( $file_name, TRUE );
		
		*/
		
        }
        
        
        public function actionDynamiccities()
        {
        	$data=Location::model()->findAll('parent_id=:parent_id',
        			array(':parent_id'=>(int) $_POST['country_id']));
        
        	$data=CHtml::listData($data,'id','name');
        	foreach($data as $value=>$name)
        	{
        		echo CHtml::tag('option',
        				array('value'=>$value),CHtml::encode($name),true);
        	}
        }
}